/*
 * @Author: gitee_com_zb
 * @Date: 2024-12-03 14:54:15
 * @LastEditors: gitee_com_zb
 * @LastEditTime: 2024-12-03 14:54:33
 * @FilePath: /algorithm/每日一题6.二叉树前序遍历(easy).cpp
 * @Description: 题目链接 https://leetcode.cn/problems/binary-tree-preorder-traversal?envType=problem-list-v2&envId=binary-tree
 */

class Solution {
public:
    void preorder(TreeNode* root, vector<int>& v) {
        if(!root) return;
        v.push_back(root->val);
        preorder(root->left, v);
        preorder(root->right, v);
    }
    vector<int> preorderTraversal(TreeNode* root) {
        vector<int> v;
        preorder(root, v);
        return v;
    }
};